import {
  getUSScore,
  fakeChartData,
  getUSScoreHistory,
} from '../../../../services/analysis_service';

export default {
  namespace: 'analysisRule',
  state: {
    offlineData: [],

    scoreHistoryData: {
      code: '',
      message: '',
      data: [],
    },

    scoreData: {
      code: '',
      message: '',
      data: [],
    },
  },

  effects: {
    *GetUSScoreHistory({ payload, callback }, { call, put }) {
      const response = yield call(getUSScoreHistory, payload);
      if (typeof response === 'undefined') {
        return;
      }
      yield put({
        type: 'saveScoreHistoryData',
        payload: response,
      });
      if (callback) callback();
    },

    *GetUSScore({ payload, callback }, { call, put }) {
      const response = yield call(getUSScore, payload);
      if (typeof response === 'undefined') {
        return;
      }
      yield put({
        type: 'saveScoreData',
        payload: response,
      });
      if (callback) callback();
    },
  },

  reducers: {
    saveScoreHistoryData(state, action) {
      return {
        ...state,
        scoreHistoryData: action.payload,
      };
    },

    saveScoreData(state, action) {
      return {
        ...state,
        scoreData: action.payload,
      };
    },
  },
};
